package com.polukeuro.app.share.request;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;

public class RequestHelper {
	
	public static void doPost(String url, String postData,
			RequestCallback requestCallback) {
		System.out.println("getting url: " + url);
		RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
		builder.setHeader("Content-Type", "application/json");
		builder.setHeader("Accept","application/json");
		try {
			Request response = builder.sendRequest(postData, requestCallback);
		} catch (RequestException e) {
			System.err.println("url: " + url + " e: " +e.getMessage());
			requestCallback.onError(null, e);
			
		}
	}

	public static void doGet(String url, RequestCallback requestCallback) {
		System.out.println("getting url: " + url);
		RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
		builder.setHeader("Content-Type", "application/json");
		builder.setHeader("Accept","application/json");
		try {
			Request response = builder.sendRequest("", requestCallback);
		} catch (RequestException e) {
			System.err.println("url: " + url + " e: " +e.getMessage());
			requestCallback.onError(null, e);
		}
	}



}
